package com.ruoyi.demo.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.demo.domain.BsTrips;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.demo.domain.vo.BsTripsVo;
import com.ruoyi.demo.domain.bo.BsTripsBo;
import com.ruoyi.demo.service.IBsTripsService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 出差信息Controller
 *
 * @author lgp
 * @date 2022-07-29
 */
@Validated
@Api(value = "出差信息控制器", tags = {"出差信息管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/trips")
public class BsTripsController extends BaseController {

    private final IBsTripsService iBsTripsService;

    /**
     * 查询出差信息列表
     */
    @ApiOperation("查询出差信息列表")
    @SaCheckPermission("demo:trips:list")
    @GetMapping("/list")
    public TableDataInfo<BsTripsVo> list(BsTripsBo bo, PageQuery pageQuery) {
        return iBsTripsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出出差信息列表
     */
    @ApiOperation("导出出差信息列表")
    @SaCheckPermission("demo:trips:export")
    @Log(title = "出差信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BsTripsBo bo, HttpServletResponse response) {
        List<BsTripsVo> list = iBsTripsService.queryList(bo);
        ExcelUtil.exportExcel(list, "出差信息", BsTripsVo.class, response);
    }

    /**
     * 获取出差信息详细信息
     */
    @ApiOperation("获取出差信息详细信息")
    @SaCheckPermission("demo:trips:query")
    @GetMapping("/{id}")
    public R<BsTripsVo> getInfo(@ApiParam("主键")
                                     @NotNull(message = "主键不能为空")
                                     @PathVariable("id") String id) {
        return R.ok(iBsTripsService.queryById(id));
    }

    /**
     * 新增出差信息
     */
    @ApiOperation("新增出差信息")
    @SaCheckPermission("demo:trips:add")
    @Log(title = "出差信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<BsTrips> add(@Validated(AddGroup.class) @RequestBody BsTripsBo bo) {
        return R.ok(iBsTripsService.insertByBo(bo));
    }

    /**
     * 修改出差信息
     */
    @ApiOperation("修改出差信息")
    @SaCheckPermission("demo:trips:edit")
    @Log(title = "出差信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<BsTrips> edit(@RequestBody BsTripsBo bo) {
        return R.ok(iBsTripsService.updateByBo(bo));
    }

    /**
     * 删除出差信息
     */
    @ApiOperation("删除出差信息")
    @SaCheckPermission("demo:trips:remove")
    @Log(title = "出差信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable String[] ids) {
        return toAjax(iBsTripsService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
